package band.wukong.practice.javase.core.io.file;

import java.io.File;
import java.io.IOException;
import java.io.BufferedInputStream;
import java.io.FileInputStream;

/**
 * Description: 读取二进制文件
 * Author: jsun
 * Date: 2010-1-4 21:37:05
 */
public class BinaryFile {
    //TODO [Undoc] 可以整理到util中。 中文不支持
    
    public static byte[] read(File file) throws IOException {
        BufferedInputStream bf = new BufferedInputStream(
                new FileInputStream(file)
        );
        try {
            byte[] data = new byte[bf.available()];
            bf.read(data);
            return data;
        } finally {
            bf.close();
        }
    }

    public static byte[] read(String file) throws IOException {
        return read(new File(file).getAbsoluteFile());
    }
    
    public static void main(String[] args) throws IOException {
        String BFILE = "E:\\ws_test\\TestJava\\src\\com\\jsun\\javase\\corepackage\\io\\testdir\\poem2.dat";
        byte[] data = read(BFILE);
        for(byte lin : data) {
            System.out.print((char)lin);
        }
    }
}
